USE [CarSharing]
GO

/****** Object:  Table [dbo].[Costos]    Script Date: 06/18/2012 00:08:35 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE Costos(
	PrecioPorKilometraje money NOT NULL
) ON [PRIMARY]

GO


/****** Object:  Table [dbo].[User]    Script Date: 06/18/2012 00:08:53 ******/
CREATE TABLE [User](
	UserId int IDENTITY(1,1) NOT NULL,
	UserName nvarchar(50) NOT NULL,
	UserPassword nvarchar(50) NOT NULL,
	Prepago bit NOT NULL,
	SaldoPrepago money NOT NULL,
	Activo bit NOT NULL,
	CONSTRAINT PK_User PRIMARY KEY CLUSTERED 
	(
		UserId ASC
	)
	WITH (
		PAD_INDEX  = OFF, 
		STATISTICS_NORECOMPUTE  = OFF, 
		IGNORE_DUP_KEY = OFF, 
		ALLOW_ROW_LOCKS  = ON, 
		ALLOW_PAGE_LOCKS  = ON
	) ON [PRIMARY],
	CONSTRAINT User_Unique UNIQUE NONCLUSTERED 
	(
		UserName ASC
	)
	WITH (
		PAD_INDEX  = OFF, 
		STATISTICS_NORECOMPUTE  = OFF, 
		IGNORE_DUP_KEY = OFF, 
		ALLOW_ROW_LOCKS  = ON, 
		ALLOW_PAGE_LOCKS  = ON
	) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [User] ADD  CONSTRAINT DF_User_SaldoPrepago  DEFAULT ((0)) FOR SaldoPrepago]
GO


/****** Object:  Table [dbo].[Trip]    Script Date: 06/18/2012 00:10:00 ******/
CREATE TABLE Trip(
	ViajeId int IDENTITY(1,1) NOT NULL,
	UserId int NOT NULL,
	Kilometraje decimal(12, 3) NOT NULL,
	CostoViaje money NOT NULL,
	Estado tinyint NOT NULL,
	CONSTRAINT PK_Trip PRIMARY KEY CLUSTERED 
	(
		ViajeId ASC
	)
	WITH (
		PAD_INDEX  = OFF, 
		STATISTICS_NORECOMPUTE  = OFF, 
		IGNORE_DUP_KEY = OFF, 
		ALLOW_ROW_LOCKS  = ON, 
		ALLOW_PAGE_LOCKS  = ON
	) ON [PRIMARY]
) ON [PRIMARY]

GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'1 = nuevo, 2 = en viaje, 3 = finalizado' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Trip', @level2type=N'COLUMN',@level2name=N'Estado'
GO

ALTER TABLE Trip  WITH CHECK ADD  CONSTRAINT FK_Trip_User FOREIGN KEY(UserId)
REFERENCES [User] (UserId)
GO

ALTER TABLE Trip CHECK CONSTRAINT FK_Trip_User
GO

